package com.wbb.controller;

import com.wbb.aop.AnLog;
import com.wbb.result.JsonResult;
import com.wbb.service.BrandService;
import com.wbb.util.pageList;
import com.wbb.util.queryParams;
import com.wbb.vo.BrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    @AnLog
    @PostMapping("/queryPage")
    public JsonResult<pageList<BrandVo>> queryPage(@RequestBody queryParams<BrandVo> params){
        pageList<BrandVo> pageList = brandService.queryPage(params);
        return JsonResult.ok().setData(pageList);
    }

    @DeleteMapping("/deleteById/{id}")
    public JsonResult deleteById(@PathVariable Long id){
        brandService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody BrandVo brandVo){
        if(brandVo.getId() != null){
            brandService.updateBrand(brandVo);
        }else {
            brandService.addBrand(brandVo);
        }
        return JsonResult.ok();
    }

    @PatchMapping("/patchDelete")
    public JsonResult patchDelete(@RequestBody List<Long> ids){
        brandService.patchDelete(ids);
        return JsonResult.ok();
    }

    @GetMapping("/getAll")
    public JsonResult<List<BrandVo>> getAll(){
        List<BrandVo> voList = brandService.getAll();
        return JsonResult.ok().setData(voList);
    }
}